import { observable, action, autorun, toJS } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx';

const { TableStore } = WeaTableNew;
import { ListStore } from './listStore';
import { WeaTools } from 'ecCom';
import * as Apis from '../apis/contacterQuery';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
export class ContacterQueryStore extends ListStore {
	@observable title = '';
    @observable rightMenu =[];

    @observable verified = false;
    @observable hasRight = false; // 权限
    @observable inited = false; //

    @action
    initDatas=(params = {}) => {
      Apis.getContacterCondition(params).then((data) => {
        if (!data.hasright && typeof (data.hasright) !== 'undefined') {
          this.hasRight = data.hasright;
          this.verified = true;
        } else {
          this.inited = true;
          this.hasRight = true;
          this.verified = true;
          this.condition = data.datas;
          this.form = new WeaForm();
          // 根据高级搜索条件初始化form
          this.form && !this.form.isFormInit && this.form.initFormFields(data.datas);
        }
      });
    }

	@action
    doSearch=(params = {}) => {
      this.loading = true;
		 // 获取表单的参数值
		 const searchParamsAd = this.form.getFormParams();
      const newParams = { ...searchParamsAd, ...params };
      Apis.getContacterList(newParams).then((data) => {
        this.tableStore.getDatas(data.sessionkey, params.current || 1);
        this.dataKey = data.sessionkey;
        this.loading = false;
      });
    }

	onShowColumn=() => { // 显示定制列
	  this.tableStore.setColSetVisible(true);
	  this.tableStore.tableColSet(true);
	}


	clearStatus=() => {
	  this.baseParams = {
	    selectType: '',
	  };
	  this.showSearchAd = false;
	  this.clearFormFields();
	}
}

